package com.example.micro.thread.queue.pool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Callable;

/**
 * 生产者线程
 *
 * @author Code Farmer
 * @create 2021/3/29 1:20 上午
 */
public class ThreadProducer implements Callable<Integer> {
    /**
     * 数据队列
     */
    ArrayBlockingQueue<Integer> dataQueue;

    public ThreadProducer(ArrayBlockingQueue<Integer> dataQueue) {
        this.dataQueue = dataQueue;
    }

    @Override
    public Integer call() throws Exception {
        int data = (int) (Math.random() * 10);  //随机生成数据
        dataQueue.put(data);   //放入数据队列中
        System.out.println("生产线程-" + Thread.currentThread().getName() + "生成数据:" + data);
        return data;
    }

}
